#!/usr/bin/env python
#coding=utf8

from threading import Thread
import time


class A(Thread):
	x = 1
	def __init__(self, lock):
		Thread.__init__(self)
		self.lock = lock
	def run(self):
		while(True):
			self.lock.acquire()
			A.x += 1
			print(threading.currentThread().getName() + "	" + str(A.x))
			time.sleep(1)
			self.lock.release()

if __name__ == "__main__":
	import threading
	lock = threading.Lock()
	a1 = A(lock)
	a2 = A(lock)
	a3 = A(lock)
	a4 = A(lock)

	a1.start()
	a2.start()
	a3.start()
	a4.start()

	a1.join()
	a2.join()
	a3.join()
	a4.join()
